<?php
include(__DIR__ . '/config.php');

use PhpAmqpLib\Connection\AMQPConnection;
use PhpAmqpLib\Message\AMQPMessage;

//设置你的连接
$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
$channel = $conn->channel();
$exchange = 'test.exchange.lu';
$key = 'test.routing.lu';

/*
    name: $queue
    passive: false
    durable: true // the queue will survive server restarts
    exclusive: false // the queue can be accessed in other channels
    auto_delete: false //the queue won't be deleted once the channel is closed.
*/
//可以设置也可以不设置
//$channel->queue_declare($queue, false, true, false, false);

/*
    name: $exchange
    type: direct
    passive: false
    durable: true // the exchange will survive server restarts
    auto_delete: false //the exchange won't be deleted once the channel is closed.
*/
$channel->exchange_declare($exchange, 'direct', false, true, false);

//$channel->queue_bind($queue, $exchange);

//你的消息
$msg_body = json_encode(array('Hello World!','php','rabbitmq'));
$properties = array(
    'content_type' => 'text/json', 
    'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT);
$message = new AMQPMessage($msg_body, $properties);

$channel->basic_publish($message, $exchange, $key);

$channel->close();
$conn->close();

?>